package com.fyb.tlog.example.feign.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Recover;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * @Author：MR.FANG
 * @name：TestRetryService
 * @Date：2025/5/12 下午5:51
 */
@Slf4j
@Service
public class TestRetryService {

    @Retryable(value = Exception.class,maxAttempts = 3,backoff = @Backoff(delay = 2000,multiplier = 1.5))
    public String test(int code) throws Exception {
        log.info("test被调用" + LocalDateTime.now());
        if (code == 0){
            throw new Exception("调用失败啦!");
        }
        log.info("test被调用，真材实料");
        return "200";
    }

    @Recover
    public String recover(Exception e,int code){
        log.info("回调方法执行");
        log.info("{}",e.getMessage());
        return "400";
    }
}
